package com.chen.apply.utils;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;

public class FieldUpdateHelper {
    public static <T> void updateCount(Class<T> entityClass, BaseMapper<T> mapper,
                                      Integer id,
                                      SFunction<T, ?> idField,
                                      String columnName,
                                      int delta) {
        LambdaUpdateWrapper<T> wrapper = new LambdaUpdateWrapper<>();
        wrapper
            .setSql(String.format("%s = %s + %d", columnName, columnName, delta))
            .eq(idField, id);
        mapper.update(null, wrapper);
    }
}
